#include "TcpServer.hpp"
#include <memory>

ServerCal handler;


void Defaultmessage(weak_ptr<Connection> con)
{
    if(con.expired()) return ;
    auto connection=con.lock();

   // std::cout << "上层得到了数据： " << connection->Inbuffer() << std::endl;
    string response_str=handler.Calculator(connection->Inbuffer());
    if(response_str.empty()) return ;//解析

    //std::cout << "响应数据是： " << response_str << std::endl;
    connection->Appendoutbuffer(response_str);//添加

    auto tcp_ptr=connection->tcp_ptr_.lock();//发送
    tcp_ptr->Send(connection);
}

int main()
{
    shared_ptr<TcpServer> srv(new TcpServer(8081,Defaultmessage));
     //用一个对象去构造，像指针一样去用
    srv->Init();
    srv->Loop();
    return 0;
}